package Interactive
{
	import EventDispatchers.ImageLoader;
	import EventDispatchers.XMLLoader;
	
	import Events.ImageEvent;
	import Events.XMLEvent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	
	import Utils.Camera;
	import Graphics.TileSet;
	
	public class InteractiveObject extends GameSprite
	{
		public function get Rect():Rectangle { return new Rectangle(worldPosition.x, worldPosition.y, 32,32);}
		
		public function InteractiveObject(game:Level, xml:String)
		{
			super(game, xml);
			this.blitRectangle =  new Rectangle(0,0,32,32);
		}
		
		protected function LoadTileMap(xml:String):void
		{
			
			var loader:ImageLoader = new ImageLoader();
			loader.addEventListener(ImageEvent.IMAGELOADED, complete);
			loader.Load(xml);
		}
		
		protected function complete(e:ImageEvent):void
		{
			var bitmap:Bitmap = e.Data;
			tileSet = new TileSet(bitmap, 32,32);
		}
		
		public override function Draw(camera:Camera, canvas:BitmapData):BitmapData
		{
			if(tileSet != null)
			{
				this.position.x = this.worldPosition.x - camera.X;
				this.position.y = this.worldPosition.y - camera.Y;
				canvas.copyPixels(tileSet.bitmapData, blitRectangle, position);
			}
			return canvas;
		}
		
		public function Interact():void
		{
		}

	}
}